package com.ss.user.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ss.common.BaseDao;
import com.ss.user.dao.RoleDao;
import com.ss.user.pojo.Role;
import com.ss.user.pojo.RoleAuthority;

@Repository("roleDao")
/**
 * 角色dao
 * 
 *
 */
public class RoleDaoImpl extends BaseDao implements RoleDao{
	/**
	 * 新增角色
	 * @param role
	 * 
	 */
	public void addRole(Role role) {
		this.getSqlMapClientTemplate().insert("role.addRole", role);
	}
	/**
	 * 更新角色
	 * @param role
	 * 
	 */
	public void updateRole(Role role) {
		this.getSqlMapClientTemplate().update("role.updateRole", role);
	}
	/**
	 * 查询角色
	 * @param role
	 * @return
	 * 
	 */
	public Role queryRole(Role role) {
		int totalRecord=0;
		if(role.pageResult.getIsPaging()){
			Object obj=this.getSqlMapClientTemplate().queryForObject("role.getRolesCount",role);
			totalRecord=Integer.parseInt(obj.toString());
			role.pageResult.setTotalRecord(totalRecord);
		}
		if(totalRecord>0 || !role.pageResult.getIsPaging()){			
			role.pageResult.setList(this.getSqlMapClientTemplate().queryForList("role.getRoles",role));
		}
		return role;
	}
	/**
	 * 查询角色根据ID
	 * @param id
	 * @return
	 * 
	 */
	@Override
	public Role queryRoleByID(String id) {
		return (Role) this.getSqlMapClientTemplate().queryForObject("role.getRoleById",id);
	}
	/**
	 * 查询角色功能关联
	 * @param roleAuthority
	 * @return
	 * 
	 */
	@Override
	public List<RoleAuthority> queryRoleAuthority(RoleAuthority roleAuthority) {
		return this.getSqlMapClientTemplate().queryForList("role.queryRoleAuthority", roleAuthority);
	}
	/**
	 * 新增角色功能关联
	 * @param roleAuthority
	 * 
	 */
	public void addRoleAuthority(RoleAuthority roleAuthority) {
		this.getSqlMapClientTemplate().insert("role.addRoleAuthority", roleAuthority);
	}
	/**
	 * 删除角色功能关联
	 * @param roleAuthority
	 */
	public void deleteRoleAuthority(RoleAuthority roleAuthority) {
		this.getSqlMapClientTemplate().delete("role.deleteRoleAuthority", roleAuthority);
	}

}
